import request from "@/utils/request";

// 发布文章
export const pubArticleAPI = (article) => {
  return request.post(`articles/`, article);
};

// 获取分类数据
export const getCategoryAPI = () => {
  return request.get("category/");
};

// 获取文章列表
export const getArticlesAPI = (params) => {
  return request.get("articles/", { params: params });
};

// 文章详情页数据
export const getArticleDetailAPI = (id) => {
  return request.get(`articles/${id}/`);
};

// 文章详情页文章内容
export const getArticleContentAPI = (id) => {
  return request.get(`content/${id}/`);
};

// 收藏文章
export const collectArticleAPI = (id) => {
  return request.post(`article/collections/${id}/`);
};

// 取消收藏文章
export const cancelCollectArticleAPI = (id) => {
  return request.delete(`article/collections/${id}/`);
};

// 修改文章信息
export const updateArticleAPI = (article, id) => {
  return request.put(`article/clicks/${id}/`, article);
};

// 文章详情页发布评论
export const pubCommentAPI = (comment) => {
  return request.post("acomments/", comment);
};

// 文章详情页获取评论
export const commentListAPI = (article_id, page) => {
  return request.get(`acomments/?page=${page}&article_id=${article_id}`);
};

// 获取评论回复列表
export const replyListAPI = (parent_id, page) => {
  return request.get(`replies/?page=${page}&parent_id=${parent_id}`);
};

export const likeCommentAPI = (target) => {
  return request.post(`comments/likes/${target}/`);
};

export const dislikeCommentAPI = (target) => {
  return request.delete(`comments/likes/${target}/`);
};

// 搜索建议
export const getSuggestListAPI = kw => {
  return request.get('suggestion/',{
    params: {
      q: kw
    }
  })
}

// 搜索文章数据
export const getSearchResultAPI = (kw, page) => {
  return request.get('search/', {
    params: {
      q: kw, // 搜索关键词
      page // 页码值
    }
  })
}